package com.chen.codesandbox.exception;

import com.chen.codesandbox.model.ExecuteCodeResponse;
import com.chen.codesandbox.model.JudgeInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler
    public ExecuteCodeResponse handleException(Exception e) {

        log.error("全局拦截器异常信息:{}", e.getMessage());
//        return Result.error(StringUtils.hasLength(e.getMessage()) ? e.getMessage() : "操作失败,请联系帅哥管理员");
        ExecuteCodeResponse executeCodeResponse = new ExecuteCodeResponse();
        executeCodeResponse.setMessage(StringUtils.hasLength(e.getMessage()) ? e.getMessage() : "提交代码失败,请联系帅哥管理员");
        // 1 编译错误
        // 3 用户提交的代码执行中存在错误
        executeCodeResponse.setStatus(1);
        return executeCodeResponse;
    }
}